import Vue from 'vue';
import VueRouter from 'vue-router';
import store from "./store.js";
import Frame from "../src/components/frame.vue";

import {
	RouterTabRoutes
} from 'vue-router-tab';

const importPage = view => () =>
	import(`../page/${view}.vue`)

Vue.use(VueRouter);

const pageRouters = [{
		path: '/', // 默认页和父级路由一致
		name: 'main',
		component: importPage('main'),
		meta: {
			title: '工作台' // 页签标题
		}
	},
	{
		path: '/user',
		name: 'user',
		component: importPage('user/list'),
		meta: {
			title: '用户列表' // 页签标题
		}
	},
	{
		path: '/role',
		name: 'role',
		component: importPage('role/list'),
		meta: {
			title: '角色列表' // 页签标题
		}
	},
	{
		path: '/permission',
		name: 'permission',
		component: importPage('permission/list'),
		meta: {
			title: '权限列表' // 页签标题
		}
	},

	{
		path: '/dept',
		name: 'dept',
		component: importPage('dept/list'),
		meta: {
			title: '部门列表' // 页签标题
		}
	},
	{
		path: '/dept/info',
		name: 'dept_info',
		component: importPage('dept/detail'),
		meta: {
			title: '部门详细' // 页签标题
		}
	},

	{
		path: '/emp',
		name: 'emp',
		component: importPage('emp/list'),
		meta: {
			title: '员工列表' // 页签标题
		}
	},
	{
		path: '/emp/info',
		name: 'emp_info',
		component: importPage('emp/detail'),
		meta: {
			title: '员工详细' // 页签标题
		}
	},
	{
		path: '/job/list',
		name: 'job_list',
		component: importPage('job/list'),
		meta: {
			title: '职位详细' // 页签标题
		}
	},
	
	
	
	{
		path: '/client',
		name: 'client',
		component: importPage('client/list'),
		meta: {
			title: '客户列表' // 页签标题
		}
	},
	
	{
		path: '/client/detail',
		name: 'client_detail',
		component: importPage('client/detail'),
		meta: {
			title: '客户详细' // 页签标题
		}
	},
	
];





const detailRouters = {
	'user_new': {
		name: 'user_new',
		component: importPage('user/new'),
		meta: {
			title: '用户新增' // 页签标题
		}
	},
	'user_detail': {
		name: 'user_detail',
		component: importPage('user/detail'),
		meta: {
			title: '用户详情', // 页签标题
		}
	},
	'role_new': {
		name: 'role_new',
		component: importPage('role/new'),
		meta: {
			title: '新增角色' // 页签标题
		}
	},
	'role_detail': {
		name: 'role_detail',
		component: importPage('role/detail'),
		meta: {
			title: '角色详细' // 页签标题
		}
	},
	'permission_new': {
		name: 'permission_new',
		component: importPage('permission/new'),
		meta: {
			title: '新增权限' // 页签标题
		}
	},
	'permission_detail': {
		name: 'permission_detail',
		component: importPage('permission/detail'),
		meta: {
			title: '权限详细' // 页签标题
		}
	},

	'dept_new': {
		name: 'dept_new',
		component: importPage('dept/new'),
		meta: {
			title: '新增部门' // 页签标题
		}
	},
	'job_detail': {
		name: 'job_detail',
		component: importPage('job/detail'),
		meta: {
			title: '职位详细' // 页签标题
		}
	},
	'job_new': {
		name: 'job_new',
		component: importPage('job/new'),
		meta: {
			title: '职位新增' // 页签标题
		}
	},


	'flow_new': {
		name: 'flow_new',
		component: importPage('flow/new'),
		meta: {
			title: '新增流程' // 页签标题
		}
	},

	'flow_detail': {
		name: 'flow_detail',
		component: importPage('flow/detail'),
		meta: {
			title: '模板详细' // 页签标题
		}
	},

	'emp_new': {
		name: 'emp_new',
		component: importPage('emp/new'),
		meta: {
			title: '新增员工' // 页签标题
		}
	},
	
};


const routes = [{
	path: '/',
	component: Frame,
	meta: {
		title: '主页' // 页签标题
	},
	children: pageRouters
}];

const router = new VueRouter({
	routes,
	pageRouters,
	detailRouters
});

router.detail = {
	open: param => {
		store.commit("openDetail", param);
	},
	close: param => {
		store.commit("closeDetail");
	}
}

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

export default router;
